<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>系统运行环境检查</title>
    {if data("cms.info.seller_id") }
    <link rel="shortcut icon" href="{data('cms.info.web_ico')}" type="image/x-icon" >
    {else}
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" >
    {/if}
    <link rel="stylesheet" href="__INSTALL_STATIC__/css/reset.css?random={extendSetting('random')}">
    <link rel="stylesheet" href="__INSTALL_STATIC__/css/common.css?random={extendSetting('random')}">
    <link rel="stylesheet" href="__INSTALL_STATIC__/css/step.css?random={extendSetting('random')}">
    <script src="__INSTALL_STATIC__/js/jquery-3.4.1.min.js?random={extendSetting('random')}"></script>
</head>
<body>
<div class="yifang-wrapper">
    <section class="yifang-section">
        <header>
            <div class="header-left">
                <h1>{if data("cms.info.seller_id")}{data('cms.info.web_name')}{else}亿坊CMS{/if}</h1>
                <h3>程序初始化设置</h3>
            </div>
            <p class="header-right">
                配置数据库连接参数、超级管理员账号及其他参数
            </p>
        </header>
        <section class="yifang-section1">
            <article class="article4">
                <h1>后台超级管理员设置</h1>
                <form id="adminForm" method="post">
                    <input type="hidden" name="step" value="install"/>
                    <table>
                        <tr>
                            <td>超级管理员名：</td>
                            <td><input id="userName" name="userName" type="text" value="{if isset($adminInput['userName']) }{$adminInput['userName']}{/if}" >建议使用8位以上数字、字母、特殊符号组合</td>
                        </tr>
                        <tr>
                            <td>超级管理员密码：</td>
                            <td><input id="userPwd" name="userPwd" type="password" value="{if isset($adminInput['userPwd']) }{$adminInput['userPwd']}{/if}" ></td>
                        </tr>
                        <tr>
                            <td>超级管理员邮件：</td>
                            <td><input id="email" name="email" type="text"value="{if isset($adminInput['email']) }{$adminInput['email']}{else}mail@yourdomain.com{/if}" >请填写超级管理员的电子邮件</td>
                        </tr>
                        <tr>
                            <td>网站访问地址：</td>
                            <td><input id="url" name="url" type="text" value="{if isset($adminInput['url']) }{$adminInput['url']}{else}{$host}{/if}" >系统自动识别，如无错误，请勿修改</td>
                        </tr>
                    </table>
                </form>
            </article>
            <footer>
                <div class="footer-left">
                    <progress value="80" max="100"></progress>
                    <span>80%</span>
                </div>
                <div class="buttons">
                    <form id="backTo" action="/install" method="post" >
                        <input type="hidden" class="step" name="step" value="4"/>
                    </form>
                    <form id="install" action="/install" method="post" >
                        <input type="hidden" class="step" name="step" value="6"/>
                        <button type="button" onclick="goBack()" >上一步(P)</button>
                        <button type="button" onclick="adminCheck()" >安装(N)</button>
                        <button type="button" onclick="if(confirm('您确定要退出安装向导吗？')) window.close();" >取消(C)</button>
                    </form>
                </div>
            </footer>
        </section>
        <div class="yifang-loader">
            <div class="loader">
                <div class="loader-inner ball-clip-rotate">
                    <div></div>
                </div>
            </div>
            系统正在安装，请稍后...
        </div>
    </section>
    {include 'install/script'}
    <script>
        /**
         * 安装
         */
        function installExec(){
            var form = document.getElementById("adminForm");
            // 用表单来初始化
            var formData = new FormData(form);
            var ok=false;
            $.ajax({
                processData:false,
                contentType :false,
//                async:false,
                cache: false,
                type:"post",
                url: "/install/exec",
                timeout: 100000,
                data:formData,
                dataType:"json",
                success:function(data)
                {
                    if(!(typeof data == "object"))
                    {
                        data=eval("("+data+")");
                    }
                    if(data.success){
                        ok=true;
                        $("#install").submit();
                    }else{
                        alert(data.codeMsg);
                    }
                },
                error:function(xhr)
                {
                    alert("安装失败");
                },
                complete:function(xhr)
                {
                    $(".yifang-loader").css({"display":"none"});
                    return false;
                }
            });
            return ok;
        }

        function sleep(time){
            var timeStamp=new Date().getTime();
            var endTime=timeStamp + time;
            while(true){
                var cutTimeStamp=new Date().getTime();
                if(cutTimeStamp > endTime){
                    break;
                }
            }
        }

        function adminCheck() {
            var userName = document.querySelector("#userName");
            var userPwd = document.querySelector("#userPwd");
            var email = document.querySelector("#email");
            var url = document.querySelector("#url");
            var ok=true;
            if (userName.value == "") {
                alert("请填写超级管理员名");
                ok= false;
            } else if (userPwd.value == "") {
                alert("请填写超级管理员密码");
                ok= false;
            } else if (email.value == "") {
                alert("请填写超级管理员邮件");
                ok= false;
            } else if (url.value == "") {
                alert("请填写网站访问地址");
                ok= false;
            }else{
                $(".yifang-loader").css({"display":"flex"});
                ok= installExec();
            }
            return false;
        }
    </script>
</div>
</body>
</html>